package com.chanjiedata.changbs.adapter;

import android.content.Context;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chanjiedata.changbs.R;
import com.chanjiedata.changbs.help.GlideHelper;
import com.chanjiedata.changbs.proto.MemberOuterClass;
import com.chanjiedata.changbs.view.MyAlbumWallGridView;

import java.text.DecimalFormat;
import java.util.List;

/**
 * 文件名 : ProgressAdapter
 * 创建者 : MangoWang
 * 创建日期 : 2019/11/25 11:50
 * 微信 : MangoWaWang
 * 邮箱 : 763482205@qq.com
 * 描述 : TODO
 */

public class MyPartnerAdapter extends BaseQuickAdapter<MemberOuterClass.my_partners_list.List, BaseViewHolder> {
    private Context mContext;

    public MyPartnerAdapter(Context context, List<MemberOuterClass.my_partners_list.List> itemList) {
        super(R.layout.item_my_partner, itemList);
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, MemberOuterClass.my_partners_list.List item) {

        GlideHelper.INSTANCE.loadAvatar(helper.getView(R.id.iv_head), item.getMemberAvatar());
        helper.setText(R.id.tv_name, item.getTruename());
        String total_price = item.getTotalPrice();
        String trading_amount = item.getTradingAmount();
        Double aDouble1 = Double.valueOf(total_price);
        Double aDouble2 = Double.valueOf(trading_amount);
        formatDouble(helper.getView(R.id.tv_money), aDouble1);
        formatDouble(helper.getView(R.id.tv_total_money), aDouble2);
        helper.setText(R.id.tv_phone, item.getMemberMobile()).setText(R.id.tv_time, item.getCreatedDate());
        helper.<MyAlbumWallGridView>getView(R.id.grid_view).setAdapter(new MarchieActionAdapter(mContext,item.getActivationInfoList()));


        // 1.获取数据
//        setProData(item.getActivationInfo(0), helper.getView(R.id.tv_h9_one), helper.getView(R.id.tv_h9_two), helper.getView(R.id.tv_one_progress));
//        setProData(item.getActivationInfo(1), helper.getView(R.id.tv_mp_one), helper.getView(R.id.tv_mp_two), helper.getView(R.id.tv_two_progress));
//        setProData(item.getActivationInfo(2), helper.getView(R.id.tv_zb_one), helper.getView(R.id.tv_zb_two), helper.getView(R.id.tv_three_progress));
//        setProData(item.getActivationInfo(3), helper.getView(R.id.tv_four_one), helper.getView(R.id.tv_four_two), helper.getView(R.id.tv_four_progress));
//        setProData(item.getActivationInfo(4), helper.getView(R.id.tv_h9_add_one), helper.getView(R.id.tv_h9_add_two), helper.getView(R.id.tv_one_add_progress));
//        setProData(item.getActivationInfo(5), helper.getView(R.id.tv_mp_add_one), helper.getView(R.id.tv_mp_add_two), helper.getView(R.id.tv_two_add_progress));
//        if (item.getActivationInfoCount() > 6)
//            setProData(item.getActivationInfo(6), helper.getView(R.id.tv_h9_plus_one), helper.getView(R.id.tv_h9_plus_two), helper.getView(R.id.tv_three_add_progress));
//        if (item.getActivationInfoCount() > 7)
//            setProData(item.getActivationInfo(7), helper.getView(R.id.tv_mp_plus_one), helper.getView(R.id.tv_mp_plus_two), helper.getView(R.id.tv_four_add_progress));
    }


    private void formatDouble(TextView view, double value) {
        DecimalFormat decimalFormat = new DecimalFormat("0.00");

        if (value >= 10000) {
            double n = value / 10000;
            view.setText("¥ " + decimalFormat.format(n) + "万");
        } else {
            view.setText("¥ " + decimalFormat.format(value));
        }
    }

    private void setProData(MemberOuterClass.my_partners_list.ActivationInfo bean_one, TextView one, TextView two, TextView name_view) {
        // 1.获取数据
        String total_stock = bean_one.getTotalStock();
        String activation = bean_one.getActivation();
        one.setText(activation);
        two.setText(total_stock);
        name_view.setText(bean_one.getName());
    }
}